home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / misc / robots.lha / player / mirobot.r < prev    next >
Text File  |  1993-04-25  |  2KB  |  122 lines

  1. UKA Studs
  2. Milano, Rob
  3. /* mirobot.r */
  4.  
  5. int rminx,rminy,rmaxx,rmaxy;
  6.  
  7. int
  8. GoodState()
  9. {
  10.   int rc;
  11.  
  12.   if (damage()>50) return 0;
  13.   else return 1;
  14. }
  15.  
  16.  
  17. int
  18. dist(x,y)
  19. int x, y;
  20. {
  21.   int a,b;
  22.  
  23.   a= loc_x()-x;
  24.   b= loc_y()-y;
  25.   return sqrt((a*a)+(b*b));
  26. }
  27.  
  28.  
  29. int nearborder()
  30. {
  31.   if ((loc_x()>980) || (loc_x()<20) || (loc_y()>980) || (loc_y()<20)) return 1;
  32.   else
  33.      return 0;
  34. }
  35.  
  36.  
  37.  
  38. int
  39. MoveIntoRectangle()
  40. {
  41.   int direction= 0;
  42.  
  43.   if (loc_x()<500)
  44.   {
  45.      if (loc_y()<500)
  46.        direction= atan((500-loc_y())/(500-loc_x())*100000);
  47.      else
  48.      if (loc_y()>500)
  49.        direction= 360+atan((500-loc_y())/(500-loc_x())*100000);
  50.   }
  51.   else
  52.   if (loc_x()>500)
  53.   {
  54.     if (loc_y()<500)
  55.        direction= 180+atan((500-loc_y())/(500-loc_x())*100000);
  56.     else
  57.     if (loc_y()>500)
  58.        direction= 180+atan((500-loc_y())/(500-loc_x())*100000);
  59.   }
  60.  
  61.  
  62.   if (direction!=0)
  63.      while(dist(500,500)>282)
  64.           drive(direction, 100);
  65.  
  66.  
  67.   drive(direction,0);
  68. }
  69.  
  70.  
  71.  
  72. int
  73. MoveRandomly()
  74. {
  75.   int i, j, maxdegree,
  76.       direction,range;
  77.  
  78.   direction= rand(359);
  79.   drive(direction,100);
  80.  
  81.   i= 0;
  82.   while(i<359) /* search whole field */
  83.   {
  84.     if (nearborder()) i=360;
  85.     else
  86.     if (range= scan(i,3))
  87.     {
  88.       cannon(i, range);
  89.       drive(direction,80);
  90.       j= i-10;
  91.       if (j<0) j+=360;
  92.       maxdegree= (j+20) % 360;
  93.       cannon(i, range+2);
  94.       while(j<maxdegree)
  95.       {
  96.         if (scan(j, 0))
  97.            cannon(j, range);
  98.         j+=2;
  99.         if (j==360) j=0;
  100.       }
  101.       i= 360;
  102.     }
  103.     i+= 5;
  104.   }
  105.   drive(0,0);
  106. }
  107.  
  108.  
  109. main()
  110. {
  111.   rminx= 300; rminy=300;
  112.   rmaxx= 700; rmaxy=700;
  113.  
  114.  
  115.   while(1)
  116.   {
  117.     MoveIntoRectangle();
  118.     MoveRandomly();
  119.   }
  120. }
  121.  
  122.